<template>
  <div class="init_main">
    <p class="name_sty">{{ name }}</p>
    <div class="query">
      科室：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="test" value="test"> </el-option>
      </el-select>
      模板类别：
      <el-select
        v-model="query.filter.SystemCategory"
        placeholder=""
        size="mini"
      >
        <el-option label="质量检查" value="质量检查"> </el-option>
        <el-option label="满意度调查" value="满意度调查"> </el-option>
      </el-select>
      模板组名称：
      <el-input
        v-model="query.input"
        placeholder=""
        size="mini"
        style="width: 150px"
      ></el-input>
      <el-button
        plain
        size="mini"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="getList"
        >查询</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-plus"
        type="primary"
        @click="open_dialog('新增')"
        >新增</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-edit"
        type="warning"
        @click="open_dialog('修改')"
        >修改</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-delete"
        type="danger"
        @click="delete_row"
        >删除</el-button
      >
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        height="600"
        highlight-current-row
        @current-change="row_click"
        v-loading="isLoading"
      >
        <el-table-column prop="Name" label="模板名称"> </el-table-column>
        <el-table-column prop="QcLevel" label="质控级别"> </el-table-column>
        <el-table-column prop="Section" label="科室"> </el-table-column>
        <el-table-column prop="Sort" label="排序"> </el-table-column>
        <el-table-column prop="Remark" label="备注"> </el-table-column>
        <el-table-column prop="附件" label="附件" v-if="false">
          <template slot-scope="scope">
            <span
              style="color: blue; border-bottom: 1px solid blue"
              v-if="scope.row.附件"
              @click="open_windo(scope.row.附件)"
              ><i style="font-size: 24px" class="el-icon-folder-checked"></i
              >查看</span
            ><span v-else>-</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange_page"
        :current-page="query.CurrentPage"
        :page-sizes="[10, 15, 50, 100]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
      >
      </el-pagination>
    </div>
    <!-- 弹层 -->
    <el-dialog
      :title="dialog_title"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <table border="1" style="width: 100%">
        <tr>
          <td class="tac">科室名称：</td>
          <td><el-input size="mini" v-model="form.Section"></el-input></td>
        </tr>
        <tr>
          <td class="tac">模板类别：</td>
          <td>
            <el-select
              v-model="form.SystemCategory"
              placeholder=""
              size="mini"
              style="width: 100%"
            >
              <el-option label="质量检查" value="质量检查"> </el-option>
              <el-option label="满意度调查" value="满意度调查"> </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td class="tac">质控类型：</td>
          <td>
            <el-select
              v-model="form.QcLevel"
              placeholder=""
              size="mini"
              style="width: 100%"
            >
              <el-option label="一级质控" value="1"> </el-option>
              <el-option label="二级质控" value="2"> </el-option>
              <el-option label="三级质控" value="4"> </el-option>
              <el-option label="一级、二级质控" value="3"> </el-option>
              <el-option label="一级、三级质控" value="5"> </el-option>
              <el-option label="二级、三级质控" value="6"> </el-option>
              <el-option label="一级、二级、三级质控" value="7"> </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td class="tac">模板组名称：</td>
          <td><el-input size="mini" v-model="form.Name"></el-input></td>
        </tr>
        <tr>
          <td class="tac">排序：</td>
          <td><el-input size="mini" v-model="form.Sort"></el-input></td>
        </tr>
        <tr>
          <td class="tac">备注：</td>
          <td>
            <el-input
              type="textarea"
              :rows="6"
              v-model="form.Remark"
            ></el-input>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">关 闭</el-button>
        <el-button type="primary" @click="btn_ok" size="mini">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      query: {
        CurrentPage: 1,
        pageSize: 10,
        total: 0,
        filter: {
          SystemCategory: "质量检查",
        },
      },
      tableData: [],
      dialogVisible: false,
      dialog_title: "",
      row_info: null,
      form: {},
      isLoading: false,
    };
  },
  mounted() {
    this.name = this.$route.meta.title;
    this.getList();
  },
  methods: {
    getList() {
      this.isLoading = true;
      this.$post("/TemplateGroup/GetPageList", this.query).then((res) => {
        this.tableData = res.Data.PageList;
        this.query.total = res.Data.Total;
        this.isLoading = false;
      });
    },
    open_windo(url) {
      window.open(url);
    },
    row_click(row) {
      if (!row) {
        this.row_info = null;
        return;
      }
      this.row_info = row;
    },
    handleClose() {
      this.form = {};
      this.dialogVisible = false;
    },
    btn_ok() {
      if (this.form.Id) {
        this.$put("/TemplateGroup/Update", this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      } else {
        this.$post("/TemplateGroup/Create", this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      }
    },
    delete_row() {
      if (this.row_info) {
        this.$get("/TemplateGroup/SoftDelete/" + this.row_info.Id).then(
          (res) => {
            this.getList();
          }
        );
      }
    },
    open_dialog(val) {
      this.dialog_title = val + "模板组";
      if (val == "新增") {
        this.dialogVisible = true;
        return;
      }
      if (val == "修改" && this.row_info) {
        this.form = this.row_info;
        console.log(this.row_info);
        this.dialogVisible = true;
      } else {
        this.$notify.error({
          title: "错误",
          message: "请选择一条数据后操作！",
        });
        return;
      }
    },
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.query.CurrentPage = 1;
    },
    handleCurrentChange_page(val) {
      this.query.CurrentPage = val;
      this.getList();
    },
  },
};
</script>

<style scoped lang='scss'>
.init_main {
  background-color: #fff;
  height: calc(100vh - 60px);
  border: 1px solid #333;
  border-radius: 5px;
  margin: 5px;
  padding: 10px;
  font-family: "FangSong";
  color: #000;
  .name_sty {
    color: #000;
    font-weight: 700;
    font-size: 18px;
    font-family: "FangSong";
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
  }
  .table {
    margin-top: 15px;
  }
  .page {
    text-align: right;
  }
}
::v-deep .el-table__body tr.current-row > td.el-table__cell {
  background-color: rgb(208, 229, 250);
  color: rgb(65, 158, 255);
  font-weight: 700;
}
.tac {
  text-align: center;
}
::v-deep .el-textarea.is-disabled .el-textarea__inner {
  color: #000 !important;
}
</style>